package pstube.download;

import pstube.main.Main;

public class Downloader {
	Main main;
	DownloadList dlList;
	
	public Downloader(Main m) {
		main = m;
	}
	
	public void addDownload(Download dl){
		dlList.addDownload(dl);
		performDownload();
	}
	
	private synchronized void performDownload(){
		Download download = dlList.getNextDownload();
		main.guiMsg("Download startet for " + download.getName());
		if(download.isValid()){
			download.perform();
		}else{
			main.guiMsg(download.getName() + " is not valid.");
		}
		if(!dlList.isEmpty()){performDownload();}
	}
}
